import http from '@/utils/http'

const BASE_URL = '/system/org'

export interface OrgResp {
  id: string
  parentId: string
  code: string
  name: string
  orgType: string
  leaderId: string
  leaderName: string
  status: 0 | 1
  children: OrgResp[]
}

export interface OrgDetailResp extends OrgResp {
  parentOrgName: string
}

export interface OrgQuery extends SortQuery {
  parentId?: string
  code?: string
  name?: string
  orgType?: Array<string>
  status?: number
}

export interface OrgPageQuery extends OrgQuery, PageQuery {

}

/** @desc 查询组织列表树 */
export function getList(query: OrgQuery) {
  return http.get<OrgResp[]>(`${BASE_URL}/list`, query)
}

/** @desc 查询组织列表树 */
export function getTree(query: OrgQuery) {
  return http.get<OrgResp[]>(`${BASE_URL}/tree`, query)
}

/** @desc 查询组织详情 */
export function getDetail(id: string) {
  return http.get<OrgDetailResp>(`${BASE_URL}/detail/${id}`)
}

/** @desc 新增组织 */
export function create(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

/** @desc 修改组织 */
export function update(data: any, id: string) {
  return http.post(`${BASE_URL}/update/${id}`, data)
}

/** @desc 排序组织 */
export function sortOrg(data: any) {
  return http.post(`${BASE_URL}/sort`, data)
}

/** @desc 删除组织 */
export function remove(id: string) {
  return http.post(`${BASE_URL}/delete/${id}`)
}
